<?php
declare (strict_types = 1);

namespace app\middleware;

use thans\jwt\facade\JWTAuth;

class Auth
{
    public function handle($request, \Closure $next)
    {
        $payload = JWTAuth::getPayload();
        $data = [];
        foreach ($payload as $key => $val) {
            if (!in_array($key, ['aud', 'exp', 'iat', 'iss', 'jti', 'nbf', 'sub'])) {
                $data[$key] = $val->getValue();
            }
        }
        $request->user = $data;
        return $next($request);
    }

}
